package user

import (
	jwt "gitee.com/sansaniot/ssiot-core/httpmvc/jwtauth"
	"github.com/gin-gonic/gin"
)

func ExtractClaims(c *gin.Context) jwt.MapClaims {
	claims, exists := c.Get(jwt.JwtPayloadKey)
	if !exists {
		return make(jwt.MapClaims)
	}

	return claims.(jwt.MapClaims)
}

func Get(c *gin.Context, key string) interface{} {
	userInfo, _ := c.Get("user")
	if userInfo == nil {
		//return nil
		// 防止服务报空异常 实际类型就是map[string]string
		return ""
	}
	userInfoMap, ok := userInfo.(map[string]interface{})
	if !ok {
		return ""
	}

	return userInfoMap[key]
}
